package com.bdsy.system.session;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;

/**
* @ClassName: SpringContextUtil 
* @Description: SpringContextUtil 工具类 
 */

public class SpringContextUtil {

	private static ApplicationContext applicationContext = null;

	public static ApplicationContext getContext() {
		return applicationContext;
	}

	public static void setContext(ApplicationContext context) {
		SpringContextUtil.applicationContext = context;
	}

	/**
	 * 根据beanId获得对象
	 * @param beanId beanID
	 * @return 返回配置的对象
	 */
	public static Object getBean(String beanId) {
		return applicationContext.getBean(beanId);
	}
	
	public static <T> T getBean(String name, Class<T> requiredType)
			throws BeansException {
		return applicationContext.getBean(name, requiredType);
	}
	
	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}
	
	public static boolean containsBean(String name) {
		return applicationContext.containsBean(name);
	}
		
	public static boolean isSingleton(String name)
	
		throws NoSuchBeanDefinitionException {
		return applicationContext.isSingleton(name);
	}
	
	public static Class<? extends Object> getType(String name)
		throws NoSuchBeanDefinitionException {
		return applicationContext.getType(name);
	}

		
	public static String[] getAliases(String name)
		throws NoSuchBeanDefinitionException {
		return applicationContext.getAliases(name);
	}
}
